﻿package top.college.cjh;

import java.awt.BorderLayout;
import java.awt.FlowLayout;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.BoxLayout;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.border.EmptyBorder;

import model.AdminVO;
import model.DepartVO;
import model.ProfessorVO;

public class Admin_Prof_Dial extends JDialog {

	private final JPanel dailMain = new JPanel();
	private static ProfessorVO newval = new ProfessorVO();
	private static JTextField get[] = new JTextField[9];
	private static Admin_Service as = new Admin_Service();
	

	public Admin_Prof_Dial ( ProfessorVO old ) {
		
		setTitle( "교수 정보 수정" );
		setBounds(100, 100, 450, 600);
		getContentPane().setLayout(new BorderLayout());
		getContentPane().add(dailMain, BorderLayout.CENTER);
	
		
		dailMain.setLayout( new GridLayout(0, 1, 0, 5) );
		
		JPanel check[] = new JPanel[9];
		JLabel admin[] =  new JLabel[9];
		
		//contentPanel.setLayout(new BoxLayout(contentPanel, BoxLayout.Y_AXIS));
		for ( int i = 0; i <= 8; i++){
			
			
			check[i] = new JPanel();
			admin[i] = new JLabel( );
			get[i] = new JTextField();
			
			// 
			check[i].setLayout( new BoxLayout(check[i], BoxLayout.X_AXIS));
			check[i].add( admin[i] );
			check[i].add( get[i] );
			get[i].setEditable(false);
			dailMain.add( check[i]);	
					
		}
		
		admin[0].setText( "순번    ");
		admin[1].setText( "교수번호  ");
		admin[2].setText( "비밀번호");
		admin[3].setText( "이름 ");
		admin[4].setText( "학과번호   ");
		admin[5].setText( "연락처  ");
		admin[6].setText( "소재지  ");
		admin[7].setText( "사무실  ");
		admin[8].setText( "생성일  ");
		
		get[0].setText( old.getProf_tr() );
		get[1].setText( old.getProf_no() );
		get[2].setText( old.getProf_pw() );
		get[3].setText( old.getProf_name() );
		get[4].setText( old.getDept_no() );
		get[5].setText( old.getProf_tel() );
		get[6].setText( old.getProf_addr() );
		get[7].setText( old.getProf_office() );
		get[8].setText( old.getReg_date() );
		
		
		
		
		
		
		{
			JPanel btnPanel = new JPanel();
			btnPanel.setLayout(new FlowLayout(FlowLayout.RIGHT));
			getContentPane().add(btnPanel, BorderLayout.SOUTH);
			
			
			{
				JButton okButton = new JButton("수정");
				// okButton.setActionCommand("OK");
				okButton.addActionListener(new ActionListener() {
					public void actionPerformed(ActionEvent e) {
					get[2].setEditable(true); // 비밀번호
					get[3].setEditable(true);	// 이름
					get[5].setEditable(true);// 전화번호
					get[7].setEditable(true);// 사무실
					
										
						
					}
				});
				btnPanel.add(okButton);
				getRootPane().setDefaultButton(okButton);
			}
			{
				JButton apBtn = new JButton("등록");
				//apBtn.setActionCommand("Cancel");
				apBtn.addActionListener(new ActionListener() {
					public void actionPerformed(ActionEvent e) {
					newval.setProf_tr( get[0].getText() );
					newval.setProf_no( get[1].getText() );
					newval.setProf_pw( get[2].getText() );
					newval.setProf_name( get[3].getText() );
					newval.setDept_no( get[4].getText() );
					newval.setProf_tel( get[5].getText() );
					newval.setProf_addr( get[6].getText() );
					newval.setProf_office( get[7].getText() );
					newval.setReg_date( get[8].getText() );
					as.updateProfVO( newval );	
					setVisible( false );
					dispose();
						
					}
				});
				
				
				btnPanel.add(apBtn);
			}
		}
		
		
	setVisible(true);	
	}

}
